import {
	MessageBox
} from 'mint-ui';

const mutations = {
	//首页轮播数据
	changesildeData(state, data) {
		state.sildeData = data
	},
	//秒杀数据
	changelimitData(state, data) {
		state.limitData = data
	},
	//商品列表数据
	changemoreData(state, data) {
		state.moreData = state.moreData.concat(data)
	},
	// 列表数据加载中样式组件
	changeloading(state, data) {
		state.loading = data
	},
	//列表数据加载完成样式组件
	changehideload(state, data) {
		state.hideload = data
	},
	//首页分类标题数据
	changecategorylistData(state, data) {
		state.categorylistData = data
	},
	//首页分类上方内容数据
	changecategoryData(state, data) {
		state.categoryData = data
	},
	//首页分类下方列表数据
	changecategorylist(state, data) {
		state.categorylist = state.categorylist.concat(data)
	},
	//分类右方数据
	changecategoryrightData(state, data) {
		state.categoryrightData = data
	},
	//分类右方内容标题图片
	changeadData(state, data) {
		state.adData = data
	},
	//分类数据ID
	changeId(state, data) {
		state.cat_id = data
	},
	//数据加载蒙版
	changeshowloading(state, data) {
		state.showloading = data
	},
	//分类列表详情数据
	changecategorydetailist(state, data) {
		state.categorydetailist = state.categorydetailist.concat(data)
	},
	//详情页数据
	changedetailData(state, data) {
		state.detailData = data
	},
	//添加购物车
	setCartDatas(state, data) {
		if (data) {
			state.cartDatas.unshift(data)
		}
		localStorage.setItem("carts", JSON.stringify(state.cartDatas))
	},
	// 点击购物车列表的单选按钮
	changeSelectStatus(state, data) {
		//购物车中的数据
		// console.log(data);
		//every()
		let selectStatus = state.cartDatas.every(item => {
			return item.isSelect == true
		})
		// console.log(selectStatus);
		state.selectAll = selectStatus
		state.cartDatas[data.index] = data.cart
		localStorage.setItem("carts", JSON.stringify(state.cartDatas))
		localStorage.setItem("selectall", JSON.stringify(state.selectAll))
	},
	//点击购物车全选按钮
	changeSelectAll(state) {
		// console.log(state.cartDatas);
		state.selectAll = !state.selectAll
		state.cartDatas.forEach(item => {
			item.isSelect = state.selectAll
		})

		localStorage.setItem("carts", JSON.stringify(state.cartDatas))
		localStorage.setItem("selectall", JSON.stringify(state.selectAll))
	},
	// 点击+
	addCartNum(state, index) {
		state.cartDatas[index].value++
		localStorage.setItem("carts", JSON.stringify(state.cartDatas))
	},
	//点击-
	jianCartNum(state, index) {

		if (state.cartDatas[index].value == 1) {
			state.cartDatas[index].value = 1
		} else {
			state.cartDatas[index].value--
		}
		localStorage.setItem("carts", JSON.stringify(state.cartDatas))
	},
	//点击删除
	deleteCart(state, index) {
		MessageBox.confirm('亲，您确定要删除此商品吗?').then(() => {
			// console.log("点击了确定按钮");
			state.cartDatas.splice(index, 1)
			localStorage.setItem("carts", JSON.stringify(state.cartDatas))
		}, () => {
			// console.log("点击了取消按钮");
		});
	},
	// 账号登陆
	changeIsLogin(state, data) {
		state.isLogin = data
	}
}
export default mutations